﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ControlLibrary;

using System.Data.SqlClient;

namespace DynamicControlLibrary
{
    public partial class HelloControl : System.Web.UI.UserControl, IEmbeddedUserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.Write(DateTime.Now);
        }

        #region IEmbeddedUserControl 成员

        public object LoadData()
        {
            throw new NotImplementedException();
        }

        public object LoadData(object obj)
        {
            Response.Write(obj);
            return obj;
        }

        public bool Save()
        {
            S(null);
            S(null);
            S(null);

            Response.Write("<div>" + GetType().GUID.ToString() + "  =====  " + this.GetHashCode() + "</div>");
            return true;
        }

        public bool S(SqlTransaction tran)
        {
            //bool returnVa

            bool newTran = tran == null;

            SqlConnection con = null;

            if (newTran)
            {
                con = new SqlConnection("Server=192.168.88.29\\sqlserver2005;Database=sjsm;Uid=sa;Pwd=sjsm2005");
                con.Open();
            }
            SqlTransaction t = tran ?? con.BeginTransaction();

            try
            {
                if (newTran)
                {
                    t.Commit();
                }
            }
            catch (Exception)
            {
                tran.Rollback();
            }
            finally
            {
                if (newTran)
                {
                    t.Connection.Close();
                }
            }
            return return
        }

        public bool Save(object obj)
        {
            S(null);
            S(null);
            S(null);
            return true;
        }

        #endregion
    }
}